package com.it.jzs.controller;

import com.it.jzs.service.UserService;
import com.it.jzs.vo.Result;
import com.it.jzs.vo.params.LoginParams;
import com.it.jzs.vo.params.RegisterParams;
import com.it.jzs.vo.params.UserUpdateParams;
import com.it.jzs.vo.params.WriteParams;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

/**
 * 注册登录控制器
 */
@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("register")
    public Result<Object> register(@RequestBody RegisterParams registerParams) {
        Result<Object> result = userService.register(registerParams);
//        System.out.println("registerParams = " + registerParams);
//        return Result.success(null, "测试");
//        new ArrayList<>()
        return result;
    }

    @PostMapping("login")
    public Result<Object> login(@RequestBody LoginParams loginParams, HttpServletRequest request) {
        Result<Object> result = userService.login(loginParams, request);
//        HttpSession session = request.getSession();
//        session
//        System.out.println("registerParams = " + registerParams);
//        r eturn Result.success(null, "测试");
//        new ArrayList<>()
        return result;
    }

    @PutMapping("")
    public Result<Object> update(@RequestBody UserUpdateParams updateParams) {
        Result<Object> result = userService.update(updateParams);
        System.out.println("registerParams = " + updateParams);
//        return Result.success(null, "测试");
//        new ArrayList<>()
        return result;
    }


}
